// 学生类

public class Student

{

    public string Name { get; set; }

    public int Id { get; set; }

    // 可添加其他学生属性

}

// 班级类（实现索引器）

public class Class

{

    private List<Student> students = new List<Student>();

    public Student this[int index]

    {

        get { return students[index]; }

        set { students[index] = value; }

    }

    public void AddStudent(Student student)

    {

        students.Add(student);

    }

    public int Count => students.Count;

}

// 测试示例

class Program

{

    static void Main()

    {

        Class class1 = new Class();

        class1.AddStudent(new Student { Name = "张三", Id = 1 });

        class1.AddStudent(new Student { Name = "李四", Id = 2 });

        // 索引访问学生

        Student s1 = class1[0];

        Student s2 = class1[1];

    }

}
